#coding=utf-8

import time
import urllib2,urllib
import ConfigParser
config = ConfigParser.ConfigParser()
config.read( './main.ini')
url = config.get('proxy','url')
url1 = config.get('proxy','url1')
url2 = config.get('proxy','url2')
def proxy_tuisong():
    print 'starting'
    while True:
        recode = urllib2.urlopen(url)
        line = recode.readlines()
        b ={}
        li =[]
        for i in line:
            i= i.split("|")
            b['proxy[%s:%s]'%(i[0],i[1])] = '%s'%(i[-1].rstrip())
        try:
            recode = urllib2.urlopen(url1,urllib.urlencode(b))
            strtt = recode.read()
            print strtt
        except Exception ,e:
            print e
        except IOError, ee:
            print ee

        try:
            recode = urllib2.urlopen(url2,urllib.urlencode(b))
            strtt = recode.read()
            print strtt
        except Exception ,e:
            print e
        except IOError, ee:
            print ee
        time.sleep(config.getint('proxy','url_proxy_time'))
if __name__=='__main__':
    proxy_tuisong()
